import request from "@/utils/request";
import { BaseResponse } from "@/api/types/baseResponse";
import { EmployeeResponse as EmployeeResponse2 } from "@/api/types/employee";

interface EmployeeInfo {
  id: number;
  username: string;
  mobile?: string;
  workNumber?: string;
  typeOfEmployment?: string;
  // ... 其他员工字段
}

interface returnDataType {
  code: string;
  data: any;
  msg: string;
}

interface EmployeeResponse {
  code: string;
  msg: string;
  data: EmployeeInfo[];
}

export function getDepartmentInfo() {
  return request({
    url: "/account/department",
    method: "get",
  });
}

//查
export function getUserInfo(deptId: number) {
  return request({
    url: "/account/employeeinfo",
    method: "get",
    params: { dept_id: deptId },
  });
}

//增加
export const addUserInfo = (data: any) => {
  return request<returnDataType,returnDataType>({
    url: "/account/employeeinfo",
    method: "post",
    data,
  });
};
//修改
export const updateUserInfo = (data: any) => {
  return request<returnDataType,returnDataType>({
    url: "/account/employeeinfo",
    method: "put",
    data,
  });
};

//删除
export const deleteUserInfo = (data: any) => {
  return request<returnDataType,returnDataType>({
    url: "/account/employeeinfo",
    method: "delete",
    data,
  });
};

// 通过部门ID查询人员
export async function getEmployeesByDepartmentId(departmentId: number) {
  return await request<
    BaseResponse<EmployeeResponse2[]>,
    BaseResponse<EmployeeResponse2[]>
  >({
    url: "/account/employeeinfo",
    params: { dept_id: departmentId },
  });
}

//查询邮箱是否重复
export const getemail = (data: any) => {
  return request<returnDataType,returnDataType>({
    url: `/email/unique?email=${data}`,
    method: "get",
  });
};

//同步激活按钮
//查询邮箱是否重复
export const getuserStatu = (data: any) => {
  return request({
    url: `/user/status?userid=${data}`,
    method: "get",
  });
};

// 通过 Excel 文件导入员工
export async function importEmployees(file: File) {
  const formData = new FormData();
  formData.append("file", file);
  return await request<BaseResponse<{}>, BaseResponse<{}>>({
    url: "/emp/file",
    method: "POST",
    data: formData,
  });
}

//续约查询
export function getrenewalInfo(userid: any) {
  return request<returnDataType, returnDataType>({
    url: `/renewal?userid=${userid}`,
    method: "get",
  });
}

//添加续约记录
export function postrenewalInfo(data: any) {
  return request<returnDataType, returnDataType>({
    url: `/renewal`,
    method: "post",
    data: data,
  });
}

//重新入职接口
export function PostReOnboarding(data: any) {
  return request<returnDataType, returnDataType>({
    url: `/entry`,
    method: "post",
    data: data,
  });
}
